/** Patient */
package domain.patient;

import java.util.Date;

import org.json.JSONObject;

import domain.user.SystemUser;
import domain.utils.JSONUtils;

/** 
 * Patients contain information about themselves 
 * @author jessienewman
 * @version 1.0
 * */
public class Patient extends SystemUser {

	/**Field address. */
	/** Field email. */
	private String email, address;
	
	/** Field dateOfBirth. */
	private Date dateOfBirth;
	
	/** Field insurance. */
	private String insurance;
	
	/** Field allergies. */
	private String allergies;
	
	/** creates a patient with no data */
	public Patient() {
		email = "";
		address = "";
		dateOfBirth = new Date();
		insurance = "";
		allergies = "";
	}
	
	/** creates a patient with only a name
	 * @param nameFirst first name
	 * @param nameMiddle middle name
	 * @param nameLast last name
	 */
	public Patient(String nameFirst, String nameLast, String nameMiddle) {
		super(nameFirst, nameLast, nameMiddle);
		email = "";
		address = "";
		dateOfBirth = new Date();
		insurance = "";
		allergies = "";
	}
	
	/** creates a patient 
	 * @param nameFirst first name
	 * @param nameMiddle middle name
	 * @param nameLast last name
	 * @param email email address
	
	 * @param dateOfBirth date of birth
	 * @param insurance patient's insurance company
	 * @param allergies list of allergies
	 * @param address String
	 */
	public Patient(String nameFirst, String nameLast, String nameMiddle, String email,  // $codepro.audit.disable largeNumberOfParameters
			String address, Date dateOfBirth, String insurance, String allergies){
			super(nameFirst, nameLast, nameMiddle);
			this.email = email;
			this.address = address;
			this.dateOfBirth = dateOfBirth;
			this.insurance = insurance;
			this.allergies = allergies;
	}

	/** creates a patient from a jsonObject
	 * @param json jsonObject to create from
	 */
	public Patient(JSONObject json) {
		super(json);
		populateFromJSON(json);
	}
	
	/**
	 * Method getEmail.
	
	 * @return String */
	public String getEmail() {
		return email;
	}

	/**
	 * Method setEmail.
	 * @param email String
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * Method getAddress.
	
	 * @return String */
	public String getAddress() {
		return address;
	}

	/**
	 * Method setAddress.
	 * @param address String
	 */
	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * Method getDateOfBirth.
	
	 * @return Date */
	public Date getDateOfBirth() {
		return dateOfBirth;
	}

	/**
	 * Method setDateOfBirth.
	 * @param dateOfBirth Date
	 */
	public void setDateOfBirth(Date dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}

	/**
	 * Method getInsurance.
	
	 * @return String */
	public String getInsurance() {
		return insurance;
	}

	/**
	 * Method setInsurance.
	 * @param insurance String
	 */
	public void setInsurance(String insurance) {
		this.insurance = insurance;
	}

	/**
	 * Method getAllergies.
	
	 * @return String */
	public String getAllergies() {
		return allergies;
	}

	/**
	 * Method setAllergies.
	 * @param allergies String
	 */
	public void setAllergies(String allergies) {
		this.allergies = allergies;
	}
	
	/** returns the json's toString
	 * @return String
	 * @see json.JSONSerializable#toString() */
	public String toString() {
		return getJSON().toString();
	}
	
	/** creates a jsonObject with information about the patient
	 * @return JSONObject about the patient * 
	 * @see json.JSONSerializable#getJSON() * 
	 */
	public JSONObject getJSON() {
		final JSONObject json = new JSONObject();
		json.put("email", email);
		json.put("address", address);
		if (dateOfBirth == null) {
			dateOfBirth = new Date(651167007);
		}
		json.put("dateOfBirth", dateOfBirth.getTime());
		json.put("insurance", insurance);
		json.put("allergies", allergies);
		return JSONUtils.merge(json, super.getJSON());
	}
}